
Mesh	=	function ()
{
	/************************************************/
	/*				Properties 						*/
	/************************************************/

		this.m_ProgramGLID;							/*!< GLSL program linked to the current mesh		*/
				
		this.m_Vertices		=	new Array();     	/*!<    Mesh's vertices         					*/
		this.m_Faces		=	new Array();       	/*!<    Mesh's face             					*/

		this.m_Entity;
		this.m_Transform	;			/*!< Shortcu to the object storing matrix transformation	*/
}

/********************************************/
/*			Static Properties 				*/
/********************************************/
	
	Mesh.Meshes = new Array();
	
/************************************************/
/*				Methods 						*/
/************************************************/

		Mesh.prototype.AddVertex=function( vertex)
		{
			this.m_Vertices.push(vertex);
		}
		
		Mesh.prototype.AddFace=function( a,  b,  c)
		{
			var face = Face.New(this.m_Vertices[a], this.m_Vertices[b], this.m_Vertices[c]);
			face.m_Mesh=this;
			this.m_Faces.push(face);
		}

		/*! brief This function will compute the normals of each face inside the Mesh    */
		Mesh.prototype.ComputeFaceNormals=function()
		{
		
		}

		/*! brief This function will compute the normals of each vertex. Standard workflow is to first compute
		 *          the faces normals, and then, for each vertex, we compute the "means" normal of each vertex link
		 *          to the current one
		 */
		Mesh.prototype.ComputeVertexNormals=function()
		{
		
		}
		
		Mesh.prototype.Display=function()
		{
			Attributes.Bind();
				gl.drawElements(gl.TRIANGLES,this.m_Faces.length*3, gl.UNSIGNED_SHORT, this.m_Faces[0].m_Offset);  //Null because we use a IBO
			Attributes.UnBind();
		}

		Mesh.NewTriangle= function(vertex1,  vertex2,  vertex3)
		{
			var mesh = new Mesh();

			mesh.AddVertex(vertex1);
			mesh.AddVertex(vertex2);
			mesh.AddVertex(vertex3);

			mesh.AddFace(0,1,2);

			BufferObject.FeedBuffers();
			
			Mesh.Meshes.push(mesh);
			
			return mesh;
		
		}

		/*! brief : Create a new rectangle. centered on zero  */
		Mesh.NewRect= function( width,  height)
		{
			var mesh  = new Mesh();
			
			var midWidth = width/2;
			var midHeight = height / 2;
			
			
			mesh.AddVertex	(
								Vertex.New	(
												new Vec4( - midWidth, midHeight, 0.0, 1.0),
												new Vec4( 0.0, 	1.0, 	1.0, 	1.0),
												new Vec4( 1.0,	1.0,	1.0,	1.0),
												new Vec4( 0.0, 	1.0, 	1.0, 	1.0)
											)
							);
							
			mesh.AddVertex	(		
								Vertex.New	(
												new Vec4(  midWidth, midHeight, 0.0, 1.0),
												new Vec4( 0.0, 	1.0, 	1.0, 	1.0),
												new Vec4( 1.0,	1.0,	1.0,	1.0),
												new Vec4( 1.0, 	1.0, 	1.0, 	1.0)
											)
							);
							
			mesh.AddVertex	(		
								Vertex.New	(
												new Vec4(  midWidth, -midHeight, 0.0, 1.0),
												new Vec4( 0.0, 	1.0, 	1.0, 	1.0),
												new Vec4( 1.0,	1.0,	1.0,	1.0),
												new Vec4( 1.0, 	0.0, 	1.0, 	1.0)
											)
							);
							
			mesh.AddVertex	(		
								Vertex.New	(
												new Vec4( - midWidth, -midHeight, 0.0, 1.0),
												new Vec4( 0.0, 	1.0, 	1.0, 	1.0),
												new Vec4( 1.0,	1.0,	1.0,	1.0),
												new Vec4( 0.0, 	0.0, 	1.0, 	1.0)
											)
							);
							
			mesh.AddFace(0,1,3);
			mesh.AddFace(3,1,2);
			
			BufferObject.FeedBuffers();
			
			Mesh.Meshes.push(mesh);
			
			return mesh;
							
		}
			
			


